<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!--linkCss-->
    <link href="index.css" type="stylesheet">
    <style>
      table{
        margin: auto;
        width: 100%;
      }
      th{
        width: 20%;
      }
      td{
        width: 20%;
        margin-right: 15px;
        text-align: center;
        letter-spacing: 0.1px;
      }
      .title-user{
        text-align: center;
        font-size:18px;
        opacity: 0.8;
        margin-top:-20px;
      }
      .add-user{
        width: 120px;
        height:34px;
        background:#5377BB;
        border:1px solid #5377BB;
        border-radius:3px;
      }
    </style>
</head>
<body>
  <a href="../add/add.html"><button class="add-user">添加用户</button></a>
  <p class="title-user">用户列表</p>
  <?php
  header("Content-type:text/html;charset=utf-8");
  date_default_timezone_set("Asia/shanghai");
  $mysql=mysqli_connect('localhost','root','root','test');
  if (mysqli_connect_errno($mysql)) {die("连接 MySQL 失败: " . mysqli_connect_error());}
  elseif(!$mysql){die("连接MySQL 失败!").mysqli_connect_error();}
  $select= "SELECT * FROM user";  //查询shopping表所有数据
  $newSelect = mysqli_fetch_array(mysqli_query($mysql,$select));
  if($newSelect == NULL){
    header("location:../error/error.php");
  }
  if ($result=mysqli_query($mysql,$select))
  {
      echo "<table border='1' width='500px'>
                  <thead>
                      <tr>
                          <th>ID</th>
                          <th>用户名</th>
                          <th>密码</th>
                          <th>添加日期</th>
                          <th>操作</th>
                      </tr>
                    </thead>
              </table>";
      while ($row=mysqli_fetch_array($result))
      {
        $row['date'] = date("Y-m-d H:i:s",$row['date']);
          echo "<table border='1' width='500px;'>
                   <tbody>
                      <tr>
                          <td>$row[id]</td>
                          <td>$row[username]</td>
                          <td>$row[password]</td>
                          <td>$row[date]</td>
                          <td>
                            <a href='../delete.php?id=$row[id]'>
                              <button>删除</button>
                            </a>
                            <a href='../edit/edit.php?id=$row[id]'>
                              <button>编辑</button>
                            </a>
                          </td>
                      </tr>
                   </tbody>
                  </table>";
      }
      mysqli_free_result($result);
  }
  mysqli_close($mysql);
  ?>
</body>
</html>
